#pragma once
#ifndef ANIMATED_SPRITE_H
#define ANIMATED_SPRITE_H

#include <string>
#include <vector>
#include <map>
#include <SFML/Graphics.hpp>

struct AnimationDefinition
{
	std::string name;

	int fps;

	std::vector<sf::IntRect> frames;
};

class AnimatedSprite : public sf::Sprite
{
public:

	AnimatedSprite(const sf::Image& img, const std::vector<AnimationDefinition>& defs);

	void update(float elapsedTime);

	void setAnimation(std::string name);

private:

	std::map<std::string, AnimationDefinition> animations;

	const AnimationDefinition* currentAnimation;

	unsigned int currentFrame;

	float animationTime;

	void nextFrame();

};

#endif //ANIMATED_SPRITE_H
